//
//  DatePickerView.m
//  MobileOffice
//
//  Created by jjkj on 16/11/1.
//  Copyright © 2016年 liaoningjujin. All rights reserved.
//

#import "DatePickerView.h"

@implementation DatePickerView


- (instancetype)initWithFrame:(CGRect)frame nowDateStr:(NSString *)nowDateStr{
    if (self=[super initWithFrame:frame]) {
        self.backgroundColor=[UIColor clearColor];
        UIView *backView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        backView.backgroundColor=[UIColor blackColor];
        backView.alpha=0.4;
        [self addSubview:backView];
        
        NSDate *nowDate=nil;
        if (nowDateStr) {
            NSDateFormatter *formatter=[NSDateFormatter new];
            [formatter setDateFormat:@"yyyy-MM-dd HH:mm"];
            nowDate=[formatter dateFromString:nowDateStr];
        }else{
            nowDate=[NSDate date];
        }
        
        FDCalendar *calendar = [[FDCalendar alloc] initWithCurrentDate:nowDate];
        __weak DatePickerView *myView=self;
        calendar.cancleBlock=^(){
            [myView removeFromSuperview];
        };
        calendar.timeStrBlock=^(NSString *timeStr){
            if (myView.sureBlock) {
                myView.sureBlock(timeStr);
            }
        };
//        CGRect frame = calendar.frame;
//        frame.origin.y = 44;
        CGFloat calendarY;
        if (IPHONE5S) {
            calendarY=563;
        }else{
            calendarY=610;
        }
        calendar.frame = CGRectMake(0, (IPHONE_HEIGHT-calendarY)/2, frame.size.width, calendar.height);
        [self addSubview:calendar];
    }
    return self;
}

- (void)dealloc{
    NSLog(@"datePickerDealloc");
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
